package org.to_zero.ssm.sdm.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.to_zero.ssm.sdm.entity.Role;
import org.to_zero.ssm.sdm.entity.vo.ResponseEntity;
import org.to_zero.ssm.sdm.mapper.RoleMapper;
import org.to_zero.ssm.sdm.service.RoleService;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Override
    public ResponseEntity handleRoleList() {
        Map<String, String> selectMap = new LinkedHashMap<>();
        List<Role> roleList = roleMapper.selectMap();
        for (Role role : roleList) {
            selectMap.put(role.getRoleCode(), role.getRoleName());
        }
        return selectMap.isEmpty() ? ResponseEntity.error() : ResponseEntity.success(selectMap);
    }
}
